package com.dd.controller;

import com.dd.dto.UserDto;
import com.dd.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("user")
@ResponseBody
public class UserController {
    @RequestMapping(value = "/save")
    public String save() {
        System.out.println("保存用户信息");
        return "用户保存";
    }

    @GetMapping(value = "/showParams")
//    @RequestMapping(value = "/showParams",method = RequestMethod.GET)
    public String showParams(@RequestParam("name") String userName, int age) {
        System.out.println("name:" + userName);
        System.out.println("age:" + age);
        return "接收Get请求参数";
    }


    @PostMapping(value = "/showPostParams")
//    @RequestMapping(value = "/showParams",method = RequestMethod.GET)
    public String showPostParams(@RequestParam("name") String userName, int age) {
        System.out.println("name:" + userName);
        System.out.println("age:" + age);
        return "接收Post请求参数";
    }

    @GetMapping("/showPojoParams")
    public User showPojoParams(UserDto userDto) {
        User user = new User();

        user.setUserName(userDto.getUserName());

        user.setAge(userDto.getAge());

        user.setAddress(userDto.getAddress());

        return user;
    }

    @PostMapping(value = "/showPojoParams1")
    public User showPojoParams1(UserDto userDto) {
        User user = new User();

        user.setUserName(userDto.getUserName());

        user.setAge(userDto.getAge());

        user.setAddress(userDto.getAddress());

        return user;
    }
}
